package org.sport.dbImplement;

import org.sport.dbInterface.AwardOperation;
import org.sport.model.entityModel.AwardtableEntity;
import org.sport.repository.AwardtableRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by Allen on 2017/9/22.
 */

@Service
public class AwardOpeImp implements AwardOperation {

    @Autowired
    AwardtableRepository    awardRepository;

    @Override
    public boolean addOneData(AwardtableEntity aw) {

        if(aw != null) {
            awardRepository.saveAndFlush(aw);
            return true;
        }
        else
            return false;
    }

    @Override
    public boolean totalAwardAddOne(AwardtableEntity aw) {
        aw = findByUserId(aw);
        aw.setTot(aw.getTot()+1);
        awardRepository.saveAndFlush(aw);
        return true;
    }

    @Override
    public boolean delOneLine(AwardtableEntity aw) {
        return false;
    }

    @Override
    public AwardtableEntity findByUserId(AwardtableEntity aw) {

        return awardRepository.findByUserId(aw.getUsertableByUserId());
    }

    @Override
    public List<AwardtableEntity> findAllUserAward() {
        return awardRepository.findAll();
    }
}
